<template>
  <div>
    <el-button type="danger" plain @click="delList()" :disabled="show">批量删除</el-button>
  </div>
</template>

<script>
import {useStore} from "vuex";
import {ref, watch} from "vue";
import axios from "axios";

export default {
  name: "MyDeleteListComponent",

  setup(){
    const store = new useStore()
    let thisPageDat = ref([])
    let show = ref(true)
    thisPageDat = store.state.questionBank.subjectModel.userSelectTestPaper
    watch(()=>store.state.questionBank.subjectModel.userSelectTestPaper,(newVal)=>{
      thisPageDat.value = newVal
      if(newVal.length === 0){
        show.value = true
      }else{
        show.value = false
      }
    },{
      deep:true
    })
     function delList(){
      //console.log(thisPageDat.value)
       let testPaperIdList = []
       thisPageDat.value.forEach(v=>{
         testPaperIdList.push(v.testPaperId)
       })
       let data = {
         testPaperIdList:testPaperIdList.toString(),

           testPaperTypeId: store.state.questionBank.subjectModel.testPaperPagination.testPaperTypeId,
           accountTypeId: store.state.questionBank.subjectModel.testPaperPagination.accountTypeId,
           status: store.state.questionBank.subjectModel.testPaperPagination.status,
           pageNumber: store.state.questionBank.subjectModel.testPaperPagination.pageNum,
           pageSize: store.state.questionBank.subjectModel.testPaperPagination.pageSize

       }
       console.log(data.testPaperIdList)
      axios.delete("/api/testPaper/deleteTestPaperList",{
        params:data
      }).then((response)=>{
        if(response.status === 200){
         if(response.data.code === 200){
           data.total = response.data.data.total
           data.pageNum = store.state.questionBank.subjectModel.testPaperPagination.pageNum
           //console.log(data)
           store.commit('setTestPaperPagination', data)
           //console.log(store.state.questionBank.subjectModel.testPaperPagination)
           store.commit('setTestPaperTableData', response.data.data.list)
         }
        }
      })
     }
    return {
      delList,
      thisPageDat,
      show
    }
  }
}
</script>

<style scoped>

</style>